<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>游戏公告</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/style/admin.css" media="all">
<body layadmin-themealias="default" style="">
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item" style="height: 20px;line-height: 20px;">
                <div class="layui-inline" style="margin-right: 0px;">
                     <span class="layui-breadcrumb">
                        <a href="">首页/游戏公告</a>
                        </span>
                </div>
                <div class="layui-inline" style="right: 0px;position: absolute;">
                    <a class="layui-btn layui-btn-small" style="line-height:20px;margin-top:-6px;float:right" href="javascript:location.replace(location.href);" title="刷新">
                        &nbsp;<i class="layui-icon layui-icon-refresh-3" style="line-height:18px;left: 12px;top:12px;"></i>&nbsp;
                    </a>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table class="layui-table" lay-filter="admin_table" id="admin_table"></table>
            <script type="text/html" id="buttonIsVerify">
                <a class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>发布公告</a>
            </script>

            <script type="text/html" id="table-useradmin-admin">
                <a class="layui-btn layui-bg-orange layui-btn-sm"  lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-normal layui-btn-sm"  lay-event="info">删除</a>
            </script>
        </div>
    </div>
</div>

<script src="__PUBLIC__/layuiadmin/layui/layui.js"></script>
<script>
    function openWin(gameid,url) {
        layer.open({
            type: 2,
            title: '信息详情',
            shadeClose: true,
            shade: 0.8,
            maxmin: true,
            area: ['70%', '60%'],
            content: '/member/'+url+'?gameid='+gameid //iframe的url
        });
    }
    layui.config({
        base: '__PUBLIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;

        $("#notice").on("click",function(){
            layer.msg('正在加载，请稍后。。', {icon: 16,shade:0.5,time:500,end:function () {
                    layer.open({
                        type: 2,
                        title:'发布公告',
                        skin: 'layui-layer-rim', //加上边框
                        area: ['25%', '40%'], //宽高
                        anim:4,
                        maxmin:true,
                        maxWidth:auto,
                        content:"/Broadcast/noticeadd",
                        btn:["确认","取消"],
                        yes:function(e,t){
                            var iform = window['layui-layer-iframe'+e],
                                submit = t.find('iframe').contents().find('#LAY-user-front-submit');
                            iform.layui.form.on('submit(LAY-user-front-submit)',function (data) {
                                var field = data.field;
                                console.log(1);
                                $.ajax({
                                    type:'post',
                                    dataType:"json",
                                    url:'/Broadcast/noticeadd',
                                    data:field,
                                    success:function (data) {
                                        if(data['code'] == 1){
                                            layer.msg(data['msg'], {icon: 1,end:function () {
                                                    layui.table.reload("admin_table");
                                                }});
                                        }else{
                                            layer.msg(data['msg'], {icon: 2,end:function () {
                                                    layui.table.reload("admin_table");
                                                }});
                                        }

                                    },
                                    error:function () {
                                        layer.msg('发生错误2', {icon: 2});
                                    },
                                });
                                layer.close(e)
                            });
                            submit.trigger('click')

                        },
                    });
                }});
        });

        table.render({
            elem: '#admin_table'
            ,url: '/Bankrecored/getnotice' //数据接口
            ,title: '游戏公告'
            ,loading:true
            ,toolbar: '#buttonIsVerify' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,page: true //开启分页
            ,cols: [[ //表头
                 {field: 'sort', align:'center', title: '公告排序', width:200}
                ,{field: 'title', align:'center', title: '公告标题', width:200}
                ,{field: 'content', align:'center', title: '公告内容'}
                ,{field: 'sendtime', title: '公告时间'}
                ,{ title: '操作', width:200,align:'center',toolbar: '#table-useradmin-admin'}

            ]]
            ,done:function (res) {

            }
        });

        //头工具栏事件
        table.on('toolbar(admin_table)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    layer.msg('正在加载，请稍后。。', {icon: 16,shade:0.5,time:500,end:function () {
                            layer.open({
                                type: 2,
                                title:'发布公告',
                                maxmin:true,
                                skin: 'layui-layer-rim', //加上边框
                                area: ['40%', '70%'], //宽高
                                anim:4,
                                resize:true,
                                content:"/Broadcast/noticeadd",
                                btn:["确认","取消"],
                                yes:function(e,t){
                                    var iform = window['layui-layer-iframe'+e],
                                        submit = t.find('iframe').contents().find('#LAY-user-front-submit');
                                    iform.layui.form.on('submit(LAY-user-front-submit)',function (data) {
                                        var field = data.field;
                                        console.log(1);
                                        $.ajax({
                                            type:'post',
                                            dataType:"json",
                                            url:'/Broadcast/noticeadd',
                                            data:field,
                                            success:function (data) {
                                                if(data['code'] == 1){
                                                    layer.msg(data['msg'], {icon: 1,end:function () {
                                                            layui.table.reload("admin_table");
                                                        }});
                                                }else{
                                                    layer.msg(data['msg'], {icon: 2,end:function () {
                                                            layui.table.reload("admin_table");
                                                        }});
                                                }

                                            },
                                            error:function () {
                                                layer.msg('发生错误2', {icon: 2});
                                            },
                                        });
                                        layer.close(e)
                                    });
                                    submit.trigger('click')

                                },
                            });
                        }});
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(admin_table)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'edit'){
                var id = '';
                id = obj.data.id;
                console.log(id);
                layer.open({
                    type: 2,
                    title:'编辑公告',
                    maxmin: true,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['40%', '70%'], //宽高
                    anim:4,
                    content:"/Broadcast/noticeupdate?id="+id,
                    btn:["确认","取消"],
                    yes:function(e,t){
                        var iform = window['layui-layer-iframe'+e],
                            submit = t.find('iframe').contents().find('#LAY-user-front-submit');
                        iform.layui.form.on('submit(LAY-user-front-submit)',function (data) {
                            var field = data.field;

                            $.ajax({
                                type:'post',
                                dataType:"json",
                                url:'/Broadcast/noticeupdate',
                                data:field,
                                success:function (data) {
                                    if(data['code'] == 1){
                                        layer.msg(data['msg'], {icon: 1,end:function () {
                                                layui.table.reload("admin_table");
                                            }});
                                    }else{
                                        layer.msg(data['msg'], {icon: 2,end:function () {
                                                layui.table.reload("admin_table");
                                            }});
                                    }

                                },
                                error:function () {
                                    layer.msg('发生错误2', {icon: 2});
                                },
                            });
                            layer.close(e)
                        });
                        submit.trigger('click')

                    },
                });
            } else if(obj.event === 'info'){
                var id = '';
                id = data.id;
                layer.confirm('真的删除吗？',function (e) {
                    $.ajax({
                        type:'get',
                        dataType:"json",
                        url:'/Broadcast/noticedelete?id='+id,
                        success:function (data) {
                            if(data['code'] == 1){
                                layer.msg(data['msg'], {icon: 1,end:function () {
                                        layui.table.reload("admin_table");
                                    }});
                            }else{
                                layer.msg(data['msg'], {icon: 2,end:function () {
                                        layui.table.reload("admin_table");
                                    }});
                            }

                        },
                        error:function () {
                            layer.msg('发生错误2', {icon: 2});
                        },
                    });
                })
            }
        });
    });
</script>
</body>
</html>